﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;

namespace TeaLightV5.Foundation.UX.Wpf.Controls
{
    public class StackPanel : System.Windows.Controls.StackPanel
    {
        public StackPanel()
        {
           
        }

        static StackPanel()
        {
            TapCommandProperty = DependencyProperty.Register("TapCommand", typeof(ICommand), typeof(StackPanel),
                new PropertyMetadata(null));
            TapCommandParameterProperty = DependencyProperty.Register("TapCommandParameter", typeof(object),
                typeof(StackPanel), new PropertyMetadata(null));
        }

        public readonly static DependencyProperty TapCommandProperty;

        public readonly static DependencyProperty TapCommandParameterProperty;


        public ICommand TapCommand
        {
            get
            {
                return (ICommand)base.GetValue(TapCommandProperty);
            }
            set
            {
                base.SetValue(TapCommandProperty, value);
            }
        }

        public object TapCommandParameter
        {
            get
            {
                return base.GetValue(TapCommandParameterProperty);
            }
            set
            {
                base.SetValue(TapCommandParameterProperty, value);
            }
        }

        private bool DoTapCommand()
        {
            ICommand tapCommand = TapCommand;
            if (tapCommand != null)
            {
                tapCommand.Execute(TapCommandParameter);
                return true;
            }
            return false;
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            e.Handled = DoTapCommand();
            base.OnMouseLeftButtonUp(e);
        }

    }
}
